<?php
declare (strict_types=1);

namespace app\backend\controller\v2;

use app\common\model\ArticleZan as ArticleZanModel;

class ArticleZan extends BaseController
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        $page = input('page/d', 1);
        $size = 10;
        $status = input('status/d', 1);
        $where = [
            ['status', '=', $status]
        ];
        $model = ArticleZanModel::where($where);
        //获取该分类下的数据
        $data = $model->with(['getmember', 'getarticle'])
            ->order('id desc')
            ->page($page, $size)
            ->select();
        //统计数量
        $rows = $model->count();
        $maxPage = ceil($rows / $size);
        foreach ($data as &$v) {
            if (empty($v->getmember)) {
                $v['member_id'] = "暂无用户名";
                $v['article_id'] = $v->getarticle->title;
                unset($v->getarticle);
            } else {
                $v['member_id'] = $v->getmember->account;
                unset($v->getmember);
                $v['article_id'] = $v->getarticle->title;
                unset($v->getarticle);
            }

        }
        return sucessMsg(200, '获取成功！', ['data' => $data, 'page' => $page, 'maxPage' => $maxPage, 'rows' => $rows]);
    }
}
